package com.right.health.app.ui.registered.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;
import com.right.health.app.bean.DoctorResponse;

/*
 * Created by hopeliao on 2019-09-24
 *
 */
public class DoctorAdapter extends BaseAbsAdapter<DoctorResponse.DoctorInfo> {

    private View.OnClickListener mClickListener;

    public void setOnClickListener(View.OnClickListener listener) {
        this.mClickListener = listener;
    }

    public DoctorAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.choose_doctor_fragment_item, null);
            viewHolder = new ViewHolder();
            viewHolder.contentImage = (ImageView) convertView.findViewById(R.id.iv_avatar);
            viewHolder.nameTv = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.levelTv = (TextView) convertView.findViewById(R.id.tv_level_name);
            viewHolder.numberTv = (TextView) convertView.findViewById(R.id.tv_number);

            viewHolder.tipsTv = (TextView) convertView.findViewById(R.id.tv_tips);
            viewHolder.handleBtn = (Button) convertView.findViewById(R.id.btn_handle);

            if(mClickListener != null) {
                viewHolder.handleBtn.setOnClickListener(mClickListener);
            }
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DoctorResponse.DoctorInfo info = mDataSource.get(position);
        viewHolder.handleBtn.setTag(info);

        viewHolder.nameTv.setText(info.doctorname);
        viewHolder.levelTv.setText(info.doctorlevel);
        viewHolder.numberTv.setText(String.format("线上挂号：%s", info.regleavecount));
        return convertView;
    }

    private class ViewHolder {
        private ImageView contentImage;
        private TextView nameTv, levelTv, numberTv;
        private TextView tipsTv;
        private Button handleBtn;
    }
}
